import Vue from "vue";
import VueRouter from "vue-router";
import login from "@/views/login";
import Home from "@/views/Home";
// import Home from '../views/Home.vue'
// import welcome from '@/views/homes/welcome'
const welcome =()=>import('@/views/homes/welcome')
const UserList =()=>import('@/views/homes/UserList')
const Power =()=>import('@/views/homes/Power')
const Roles =()=>import('@/views/homes/Roles')
const GoodsClass =()=>import('@/views/homes/goods/GoodsClass')
const GoodsParam =()=>import('@/views/homes/goods/GoodsParam')
const GoodsList =()=>import('@/views/homes/goods/GoodsList')
const AddGoods =()=>import('@/views/homes/goods/AddGoods')
const Order =()=>import('@/views/homes/Order/Order')
const DataList =()=>import('@/views/homes/DataList/DataList')
const book =()=>import('@/views/homes/book/book')
const bookAdd =()=>import('@/views/homes/book/bookAdd')
const bookLook =()=>import('@/views/homes/book/bookLook')

Vue.use(VueRouter);

const routes = [
  {
    path: "",
    redirect: "/Login",
  },
  {
    path: "/Login",
    component: login,
  },
  {
    path: "/Home",
    component: Home,
    redirect: "/welcome",
    children: [
      {
        path: "/welcome",
        component: welcome,
      },
      {
        path: "/UserList",
        component: UserList,
      },
      {
        path: "/Roles",
        component: Roles,
      },
      {
        path: "/Power",
        component: Power,
      },
      {
        path: "/GoodsClass",
        component: GoodsClass,
      },
      {
        path: "/GoodsParam",
        component: GoodsParam,
      },
      {
        path: "/GoodsList",
        component: GoodsList,
      },
      {
        path: "/GoodsList/AddGoods",
        component: AddGoods,
      },
      {
        path: "/Order",
        component: Order,
      },
      {
        path: "/DataList",
        component: DataList,
      },
      {
        path: '/book',
        component:book
      },
      {
        path: '/bookAdd',
        component:bookAdd
      },
      {
        path: '/bookLook',
        component:bookLook
      },
      
    ]
  },
  // {
  //   path: '/about',
  //   name: 'About',
  //   route level code-splitting
  //   this generates a separate chunk (about.[hash].js) for this route
  //   which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
];

const router = new VueRouter({
  routes,
  // mode :'history'
})

router.beforeEach((to, from, next) => {
  if (to.path === "/Login") return next();
  const tokener = window.sessionStorage.getItem("token");
  if (!tokener) return next("/Login");
  next();
});

export default router;
